package com.xqkad.myplayer.service;

import android.app.ActivityManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.xqkad.myplayer.utils.PreferencesUtility;

import java.util.List;

public class LogService extends Service {
    protected static final String TAG = "mytag";
    protected static final boolean D = false;

    @Override
    public void onCreate() {
        if (D) Log.d(TAG, "onCreate: ");
        super.onCreate();
        //createlog();
    }

    String createlog(){
        String c = PreferencesUtility.getServiceCreateTime(this);
        String d = PreferencesUtility.getServiceDestroyTime(this);

        long cl = Long.valueOf(c);
        long dl = Long.valueOf(d);
        long cul = System.currentTimeMillis();
        String s = PreferencesUtility.makeTimeString2(dl-cl);
        //Log.d(TAG,"上次运行时间："+s);
        s = PreferencesUtility.makeTimeString2(cul-cl);
        Log.d(TAG,"上次创建时间："+s+"前");
        s = PreferencesUtility.makeTimeString2(cul-dl);
        Log.d(TAG,"上次销毁时间："+s+"前");
        PreferencesUtility.setServiceCreateTime(this);
        return c;
    }

    @Override
    public IBinder onBind(Intent intent) {
        if (D) Log.d(TAG, "onBind: ");
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (D) Log.d(TAG, "onStartCommand: ");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public boolean onUnbind(Intent intent) {
        if (D) Log.d(TAG, "onUnbind: ");
        return super.onUnbind(intent);
    }

    @Override
    public void onRebind(Intent intent) {
        if (D) Log.d(TAG, "onRebind: ");
        super.onRebind(intent);
    }

    @Override
    public void onDestroy() {
        if (D) Log.d(TAG, "onDestroy: ");
        Log.d(TAG, "onDestroy: ");
        super.onDestroy();
        PreferencesUtility.setServiceDestroyTime(this);
        PreferencesUtility.setServiceLifeTime(this);
        String s = PreferencesUtility.getServiceLifeTime(this);
        s = PreferencesUtility.makeTimeString2(Integer.valueOf(s));
        Log.d(TAG,"service onDestroy: "+s);
    }
}
